package com.huang.core.widget.edittext

import android.text.Editable
import java.lang.Exception

open class PercentTextChangeListener : SimpleTextChangeListener() {
    override fun afterTextChanged(s: Editable) {
        var result = s.toString()
        val doubleTemp = try {
            result.toDouble()
        } catch (e: Exception) {
            0.0
        }

        if (doubleTemp.compareTo(0) < 0) {
            result = "0"
            s.replace(0, s.length, result)
        }
        else if (doubleTemp.compareTo(1) > 0) {
            result = "1"
            s.replace(0, s.length, result)
        }

        afterFilter(s)
    }

    open fun afterFilter(s: Editable) {

    }
}